<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>南京大学职业咨询室预约平台</title>
    <!-- Set render engine for 360 browser -->
    <meta name="renderer" content="webkit">
    <!-- No Baidu Siteapp-->
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/x-icon" href="{{ url_for('static', filename='assets/i/ico_128X128.ico') }}">
    <!-- Add to homescreen for Chrome on Android -->
    <meta name="mobile-web-app-capable" content="yes">
    <link rel="icon" sizes="192x192" href="{{ url_for('static', filename='assets/i/app-icon72x72@2x.png') }}">
    <!-- Add to homescreen for Safari on iOS -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="apple-touch-icon-precomposed" href="{{ url_for('static', filename='assets/i/app-icon72x72@2x.png') }}">
    <!-- Tile icon for Win8 (144x144 + tile color) -->
    <meta name="msapplication-TileImage" content="{{ url_for('static', filename='assets/i/app-icon72x72@2x.png') }}">
    <meta name="msapplication-TileColor" content="#0e90d2">

    <link rel="stylesheet" href="{{ url_for('static', filename='assets/css/amazeui.min.css') }}">
    <link rel="stylesheet" href="{{ url_for('static', filename='assets/css/app.css', v='1.4') }}">
    <script src="{{ url_for('static', filename='assets/js/jquery.min.js') }}"></script>
    <script src="{{ url_for('static', filename='assets/js/amazeui.min.js') }}"></script>
</head>

<body>
<div class="admin-header">
    <!--<div class="header-back" onclick="history.back()">返回</div>-->
    <div class="header-title">学生名单</div>
</div>
<div class="content">
    {% for li in lists %}
    <div class="book-item-warp">
        <div class="book-item-title">
            <div class="fl"> <strong>编号：</strong>{{li['id']}}</div>
        </div>
        <div class="book-item-line">
            <div class="fl"> <strong>学生姓名：</strong>{{ li['name'] }}</div>
            <div class="fr"> <strong>性别：</strong>{{ li['sex'] }}</div>
        </div>
        <div class="book-item-line">
            <div class="fl"> <strong>手机号：</strong>{{li['contact']}}</div>
            <div class="fr"> <strong>学号：</strong>{{li['stuID']}}</div>
        </div>
        <div class="book-item-line">
            <div class="fl"> <strong>所在院系：</strong>{{li['department']}}&nbsp;{{li['major']}}&nbsp;{{li['grade']}}</div>
        </div>
         <div class="book-item-line">
            <div class="fl"> <strong>咨询日期：</strong>{{li['date']}}</div>
            <div class="fr"> <strong>教师姓名：</strong>{{li['tchname']}}</div>
        </div>
        <div class="book-item-line">
            <div class="fl"> <strong>学生状态：</strong>{{li['status']}}</div>
            <div class="fr"> <strong>设置：</strong><select id="status_op_{{li['id']}}"><option value="">学生状态</option><option value="2">正常预约</option><option value="3">限制使用</option>
            </select><button value="{{li['id']}}" tele="{{li['contact']}}" onClick="set_stu_st(this.value,this)" class="del_stu am-btn-primary">保存</button>
            </div>
        </div>
        <div class="book-item-line">
            <div class="fl"> <strong>取消次数：</strong>{{li['cans']}}</div>
            <div class="fr"> <strong>操作：</strong> <button value="{{li['contact']}}" onClick="delete_student(this.value)" class="del_stu am-btn-danger">删除</button></div>
        </div>
     </div>
     {% endfor %}

    <div class="am-cf">
        <button type="text" id="back_" value="返回" onclick="javascript:window.location.href='./admin_center';" class="am-btn am-btn-default">返&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;回</button>
    </div>

    <form method="post" action="/">

    </form>
</div>

<script type="text/javascript">
    function set_stu_st(val, obj)
    {
        if ($("#status_op_"+val).val()=="") {
            alert("保存之前请先选择学生状态！");
            return false;
        };

        var csrftoken = $('meta[name=csrf-token]').attr('content');
        $.ajaxSetup({
            beforeSend: function(xhr, settings) {
                if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
                    xhr.setRequestHeader("X-CSRFToken", csrftoken)
                }
            }
        });
        $.ajax({
            // 请求发送方式
            type: 'post',
            // 验证文件
            url: '/set_stu_status',
            // 用户输入的帐号密码
            data: {
                'contact': $(obj).attr("tele"),
                'status': $("#status_op_"+val).val()
            },
            // 异步，不写默认为True
            async: 0,
            //请求成功后的回调
            success: function(data) {
                alert("设置学生状态成功！");
                window.location.reload();
            },
            error: function() {
                alert('服务端异常');
            }
        });
    }

    function delete_student(val)
    {
        conf = window.confirm("确定删除该学生用户？");
        if (conf) {
            var csrftoken = $('meta[name=csrf-token]').attr('content');
            $.ajaxSetup({
                beforeSend: function(xhr, settings) {
                    if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
                        xhr.setRequestHeader("X-CSRFToken", csrftoken)
                    }
                }
            });
            $.ajax({
                // 请求发送方式
                type: 'post',
                // 验证文件
                url: '/delete_student',
                // 用户输入的帐号密码
                data: {
                    'contact': val
                },
                // 异步，不写默认为True
                async: 0,
                //请求成功后的回调
                success: function(data) {
                    alert("成功删除学生用户！");
                    window.location.reload();
                },
                error: function() {
                    alert('服务端异常');
                }
            });
        };
    }
</script>
</body>

</html>
